package Chapter7_MultiplexingClass;

/**
 * Date: 2019/2/18
 * Time: 19:39
 * User: Driss.
 *
 *  7.8.2 final方法 final private 方法
 */

class WithFinals{
    //Identical to "private" alone:
    private final void f(){
        System.out.println("WithFinals.f()");
    }
}

class OverridingPrivate extends WithFinals{
    private final void f(){
        System.out.println("OverridingPrivate.f()");
    }

    private void g(){
        System.out.println("OverridingPrivate.g()");
    }
}

class OverridingPrivate2 extends OverridingPrivate{
    public final void f(){
        System.out.println("OverridingPrivate2.f()");
    }
    public void g(){
        System.out.println("OverridingPrivate2.g()");
    }
}


public class FinalOverridingIllusion {
    public static void main(String[] args) {
        OverridingPrivate2 op2 = new OverridingPrivate2();
        op2.f();
        op2.g();

        // you can upcast
        OverridingPrivate op = op2;

        //but you can't call the methods:
        //!op.f();
        //!op.g();
        //Same here:
        WithFinals wf = op2;
        //!wf.f()
        //!wf.g();
    }
}
